package com.liesheng.haylou.ui.setting;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.SeekBar;

import androidx.databinding.DataBindingUtil;

import com.liesheng.daemonlib.LogUtil;
import com.liesheng.haylou.R;
import com.liesheng.haylou.base.BaseActivity;
import com.liesheng.haylou.base.BaseFunActivity;
import com.liesheng.haylou.databinding.ActivitySettingEqBinding;
import com.liesheng.haylou.ui.setting.vm.SetttingEqVm;
import com.liesheng.haylou.view.MyHorizontalScrollView;

/**
 * Date:2019/11/27
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description:
 */
public class SetttingEqActivity extends BaseActivity<ActivitySettingEqBinding, SetttingEqVm> {
    @Override
    protected ActivitySettingEqBinding getmBinding() {
        mBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.activity_setting_eq, null, false);
        return mBinding;
    }

    @Override
    protected SetttingEqVm getViewModel() {
        return new SetttingEqVm(this);
    }

    @Override
    protected void initData() {
        setTitle(R.string.eq);
        setStatusBarColor(R.color.color_0A0B0C,true);
        head_middle.setTextColor(Color.WHITE);
        String address = getIntent().getStringExtra("address");
        mVm.addEqItem();
        mVm.setAddress(address);
        mBinding.horizontalScrollView.setScrollViewListener(new MyHorizontalScrollView.ScrollViewListener() {
            @Override
            public void onScrollChanged(MyHorizontalScrollView.ScrollType scrollType) {
                if (scrollType == MyHorizontalScrollView.ScrollType.IDLE) {
                    mVm.scrollToNearView();
                }
            }
        });

        initSeekBar(mBinding.seekBar1);
        initSeekBar(mBinding.seekBar2);
        initSeekBar(mBinding.seekBar3);
        initSeekBar(mBinding.seekBar4);
        initSeekBar(mBinding.seekBar5);
    }

    public static void startBy(BaseFunActivity activity,String address) {
        Intent intent = new Intent(activity, SetttingEqActivity.class);
        intent.putExtra("address",address);
        activity.startActivityForResult(intent,0);
    }

    public static void startBy(BaseFunActivity activity,String address , int position) {
        Intent intent = new Intent(activity, SetttingEqActivity.class);
        intent.putExtra("address",address);
        intent.putExtra("position",position);
        activity.startActivity(intent);
    }

    @Override
    public void onClickView(View view) {

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            mVm.initBezierPointX();
        }
    }

    private void initSeekBar(SeekBar seekBar) {
        seekBar.setMax(10000);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                mVm.updateBezierView();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                mVm.setWrite2Device(true);
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                mVm.setWrite2Device(false);
//                seekBar.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        mVm.updateCustomize();
//                    }
//                },80);
            }
        });
    }
}
